<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="box">
    <div class="box-body">
    <p>
        <?= Html::a('添加文章', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel, 
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            /**
            [
              'attribute' => 'cid',
              'value' => function($model) {
                return $model->category->title;
              }
            ],
            */
            'title',
            'sort',
            [
                'attribute' => 'status',
                'value' => function ($model) {
                    if (!$model->status) {
                        return 0;
                    }
                    return \Yii::$app->params['article_status'][$model->status];
                },
                'filter' => \Yii::$app->params['article_status']
            ],

            'created_at:datetime',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
</div>
